package apiday02.collection;

import java.util.HashSet;
import java.util.LinkedHashSet;

public class HashSetDemo {
    public static void main(String[] args) {
        HashSet<Point> hashSet = new HashSet<>();//无序
        hashSet.add(new Point(1,2));
        hashSet.add(new Point(4,12));
        hashSet.add(new Point(2,8));
        hashSet.add(new Point(8,9));
        boolean b = hashSet.add(new Point(2,8));//通过equals()和hashCode()一起判断
        System.out.println(b);//false
        System.out.println(hashSet);
        System.out.println("-------------------------------");

        LinkedHashSet<Point> linkedHashSet = new LinkedHashSet<>();//有序
        linkedHashSet.add(new Point(1,2));
        linkedHashSet.add(new Point(4,12));
        linkedHashSet.add(new Point(2,8));
        linkedHashSet.add(new Point(8,9));
        boolean flag = linkedHashSet.add(new Point(2,8));
        System.out.println(flag);//false
        System.out.println(linkedHashSet);


    }
}
